<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 26355
  Date: 2019/1/19
  Time: 13:40
  邮件首页
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>消息中心</title>
    <link rel="stylesheet" href="/layui-2.4/layui-v2.4.5/layui/css/layui.css">
    <%@include file="button.jsp"%>
</head>
<body>
<div class="layui-btn-group demoTable">
    <button class="layui-btn layui-btn-primary layui-btn-sm" data-type="checkDataTo1">标记已读</button>
    <button class="layui-btn layui-btn-primary layui-btn-sm" data-type="checkDataTo0">标记未读</button>
    <button class="layui-btn layui-btn-primary layui-btn-sm" data-type="write">写邮件</button>

</div>
<table class="layui-hide" id="fontMessage" lay-filter="test"></table>

<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="/layui-2.4/layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#fontMessage'
            ,url:'/fontMessageHome?state=${requestScope.state}&operate=${requestScope.operate}&sendReceive=${requestScope.sendReceive}'
            ,cols: [[
                {type:'checkbox',file:'left'}
                ,{field:'title', width:800, title: '标题内容',event:'readEmail', sort: false}
                ,{field:'time', width:150, title: '时间', sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:100,align: 'right'}
            ]]
            ,page: true
            ,limits:[3,5,10]
        });

        //选中数据操作

        var $ = layui.$, active = {//修改消息状态为已读
            checkDataTo1: function(){ //获取选中数据并将数据传入到修改界面
                var checkStatus = table.checkStatus('fontMessage')
                    ,data = checkStatus.data;

                var messageId=new Array();
                for (var i=0;i<data.length;i++){
                    messageId[i]=data[i].messageId;
                }
                if (0!=data.length) {
                    window.location.href="/parameter?operate=update&messageId="+messageId+"&state=1";//update
                }else {
                    layer.alert("请选择至少一条消息");
                }

            }
            ,checkDataTo0: function(){ //修改消息状态为未读
                var checkStatus = table.checkStatus('fontMessage')
                    ,data = checkStatus.data;

                var messageId=new Array();
                for (var i=0;i<data.length;i++){
                    messageId[i]=data[i].messageId;
                }
                if (0!=data.length) {
                    window.location.href="/parameter?operate=update&messageId="+messageId+"&state=0";//update
                }else {
                    layer.alert("请选择至少一条消息");
                }

            }
            ,write: function(){ //转入写邮件页面
                var checkStatus = table.checkStatus('fontMessage')
                    ,data = checkStatus.data;

                window.location.href="jsp/hd/writeEmail.jsp";

            }

        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('确认删除邮件吗?', function(index){

                    window.location.href="/parameter?operate=delete&messageId="+data.messageId;

                    // layer.close(index);
                });
            }else if (obj.event==='readEmail'){
                window.location.href="/parameter?operate=catEmailContent&time="+data.time+"&title="+data.title+"&message="+data.message;//传入参数catEmailContent表示操作类型为查看邮件内容

            }
        });
    });
</script>

</body>
<script>
    function home() {
        window.location.href="/parameter?state=3&operate=select";
    }
    function readed() {
        window.location.href="/parameter?state=1&operate=select";
    }
    function unread() {
        window.location.href="/parameter?state=0&operate=select";
    }
    function send() {//发件箱
        window.location.href="/parameter?sendReceive=0&operate=select";
    }
    function receive() {//收件箱
        window.location.href="/parameter?sendReceive=1&operate=select";
    }
</script>
</html>
